var basePath = $("#basePath").val();
var countAnswerItemOne = 0;
var countAnswerCommon = 0;
$(document).ready(function () {
    countAnswerItemOne = parseInt($("#countAnswerItemOne").val());
    countAnswerCommon = parseInt($("#countAnswerCommon").val());
    // 增加主治答案项
    $("#addMayorCrueButton").click(function () {
        if (countAnswerItemOne > 5) {
            // 询问框
            layer.confirm('主治项已达上限！', {
                btn: ["确认"]
                // 按钮
            });
        } else {
            var content = "<div class='form-group'><div class='col-sm-2'><i onclick='deleteNewAddA(this)' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div><div class='col-sm-6'><input type='text' class='form-control' name='commonAnswerList[" + countAnswerItemOne + "].answer'placeholder='请输入主治答案......' /></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2'><input type='number' class='form-control' name='commonAnswerList[" + countAnswerItemOne + "].score'/></div><div class='col-md-1'></div></div>";
            $("#mayorCure").parent().append(content);
            countAnswerItemOne = countAnswerItemOne + 1;
        }
    });

    // 增加答案项
    $("#addCommonAnswerButton").click(function () {
        if (countAnswerCommon > 5) {
            // 询问框
            layer.confirm('答案项已达上限！', {
                btn: ["确认"]
                // 按钮
            });
        } else {
            var content = "<div class='form-group'><div class='col-sm-2'><i onclick='deleteNewAddB(this)' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div><div class='col-sm-6'><input type='text' class='form-control' name='commonAnswerList[" + countAnswerCommon + "].answer'placeholder='请输入答案项......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2'><input type='number' class='form-control' name='commonAnswerList[" + countAnswerCommon + "].score'/></div><div class='col-md-1'></div></div>";
            $("#anserTerm").parent().append(content);
            countAnswerCommon = countAnswerCommon + 1;
        }
    });
});

function deleteNewAddA(data) {
    $(data).parent().parent().remove();
    countAnswerItemOne = countAnswerItemOne - 1;
}

function deleteNewAddB(data) {
    $(data).parent().parent().remove();
    countAnswerCommon = countAnswerCommon - 1;
}

/**
 *@Author: 陈玉林
 *@Description: 验证提干是否重复
 *@Date: 2017/8/10 12:54
 */

/*===================================验证提干是否重复=========================================*/
function validateStemForUpdateExam(id, category, stem) {
    var result = false;
    if (stem == '') {
        layer.confirm('试题题干不可为空！', {
            btn: ["确认"]
        });
        return result;//题干为空不发送请求
    }
    $.ajax({
        type: "POST",
        url: basePath + '/examination/validateStemForUpdateExam',
        data: {id: id, stem: stem, category: category},
        dataType:"JSON",
        async: false,
        success: function (data) {
            if (data.code == 1) {//若是试题题干重复提示更改
                layer.confirm('该试题题干与其它试题题干冲突，请修改输入题干！', {
                    btn: ["确认"]
                });
            } else {
                layer.msg('试题题干可用', {
                    icon: 1,
                    time: 3000
                });
                result = true;
            }
        }
    });
    return result;
}

/*===================================验证提干是否重复=========================================*/

